$(document).ready(function(){
    initZTree();
});
var setting = {
    async: {
        enable: true,
        url:"http://localhost:8081/base/tree/asyncGetNodes",
        autoParam:["id", "pid", "name"],
        dataFilter: filter
    },
    data:{
        simpleData:{
            enable: true,
            idKey:'id',
            pIdKey:'pid',
            rootPId: 0
        }
    },
    view:{
        showIcon: false
    }
};
function filter(treeId, parentNode, childNodes) {
    return childNodes;
}
//初始化树
function initZTree(){
    $.ajax({
        url:"http://localhost:8081/base/tree/getDepartTree",
        type:"post",
        dataType: "json",
        success: function(data){
            console.log(data);
            var zTreeObj = $.fn.zTree.init($("#zTree"),setting, data);
            //让第一个父节点展开
            var rootNode_0 = zTreeObj.getNodeByParam('pid',0,null);
            zTreeObj.expandNode(rootNode_0, true, false, false, false);
        },
        error: function(e){
            console.log(e)
        }
    });
}